package listen

import (
	"fmt"
	"net"
	"time"

	"myOJ/transmit"
)

func listening() {

}

func haveErr(err error) bool {
	if err != nil {
		return true
	} else {
		return false
	}
}

func OpenListen() int {
	PORT := ":10111"
	tcpAddr, err := net.ResolveTCPAddr("tcp4", PORT)
	if err != nil {
		fmt.Println(err)
		return -1
	}

	listener, err := net.ListenTCP("tcp", tcpAddr)
	if err != nil {
		fmt.Println(err)
		return -1
	}
	print("Deployment was successful!\n")
	for {
		conn, _ := listener.Accept()
		defer conn.Close()
		print("A new connection in " + time.Now().String() + " \n")
		go transmit.Getconn(conn)
	}

}
